package com.winfar.ic.helper;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import android.os.Environment;

public class FileSDHelper implements FileSDInterface{
	private String SDPATH;
	
	public FileSDHelper() {
		File skRoot = Environment.getExternalStorageDirectory();
		SDPATH = skRoot.getPath() + "\\";
	}
	
	@Override
	public File creatSDFile(String fileName) throws IOException {
		return FileHelper.creatFile(SDPATH + fileName);
	}

	@Override
	public boolean delSDFile(String fileName) {
		return FileHelper.delFile(SDPATH + fileName);
	}

	@Override
	public File creatSDDir(String dirName) {
		return FileHelper.creatDir(SDPATH + dirName);
	}

	@Override
	public boolean delSDDir(String dirName) {
		return FileHelper.delDir(SDPATH + dirName);
	}

	@Override
	public boolean renameSDFile(String oldfileName, String newFileName) {
		return FileHelper.renameFile(SDPATH + oldfileName, SDPATH + oldfileName);
	}

	@Override
	public boolean copySDFileTo(String srcFileName, String destFileName)
			throws IOException {
		return FileHelper.copyFilesTo(SDPATH + srcFileName, SDPATH + destFileName);
	}

	@Override
	public boolean copySDFilesTo(String srcDirName, String destDirName)
			throws IOException {
		return copySDFilesTo(SDPATH + srcDirName, SDPATH + srcDirName);
	}

	@Override
	public boolean moveSDFileTo(String srcFileName, String destFileName)
			throws IOException {
		return FileHelper.moveFilesTo(SDPATH + srcFileName, SDPATH + destFileName);
	}

	@Override
	public boolean moveSDFilesTo(String srcDirName, String destDirName)
			throws IOException {
		return FileHelper.moveFilesTo(SDPATH + srcDirName, SDPATH + destDirName);
	}

	@Override
	public void writeSDFile(String fileName,String content) throws IOException {
		File file = new File(SDPATH + fileName);
		FileOutputStream fos = new FileOutputStream(file);
		FileHelper.writeFile(fos, content);
	}

	@Override
	public void appendSDFile(String fileName,String content) throws IOException {
		File file = new File(SDPATH + fileName);
		FileOutputStream fos = new FileOutputStream(file, true);
		FileHelper.writeFile(fos, content);
	}

	@Override
	public byte[] readSDFile(String fileName) throws IOException {
		File file = new File(SDPATH + fileName);
		FileInputStream fis = new FileInputStream(file);
		return FileHelper.readFile(fis);
	}
}
